package com.example.mypotiota_si.Adapter;

import android.content.Context;
import android.text.Layout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mypotiota_si.Datas.CanGuan;
import com.example.mypotiota_si.R;

import java.util.ArrayList;

public class ListViewAdapter_wm_cg extends RecyclerView.Adapter<ListViewAdapter_wm_cg.ViewHolder> {
    ArrayList<CanGuan> canGuan;
    String TAG="ListViewAdapter_wm_cg";
    Context context;


    public ListViewAdapter_wm_cg(ArrayList<CanGuan> canGuan,Context context) {
        this.canGuan = canGuan;
        this.context=context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wm_cg_list_view,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.setData(canGuan.get(position));
//        holder.cg_name.setText(canGuan.get(position).cg_name+"");
//        Log.i(TAG,canGuan.get(position).cg_name);
    }

    @Override
    public int getItemCount() {
        if (canGuan!=null){
            return canGuan.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView cg_name;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            cg_name=itemView.findViewById(R.id.cg_name);
        }

        public void setData(CanGuan canGuan) {
            cg_name.setText(canGuan.cg_name);
        }
    }
}
